package com.ericzong.renamer.converter.file;

import org.apache.commons.io.FilenameUtils;

import com.ericzong.renamer.converter.string.DelStringConverter;
import com.ericzong.renamer.model.Record;

public class DelPathConverter extends DelStringConverter 
{

	@Override
	public void convert(Record record) 
	{
		StringBuffer target = new StringBuffer(record.getSource());
		
		if(getLength() != 0)
		{
			String baseName = FilenameUtils.getBaseName(record.getSource());
			int baseLength = baseName.length();
			
			int start = getIndex(getStartIndex(), baseLength);
			int end = getIndex(start + getLength(), baseLength);
			target.delete(start, end);
		}
		
		record.setTarget(target.toString());
	}

}
